package thread;

class MyThread3 implements Runnable {
    @Override
    public void run() {
        while(true) {
            System.out.println("hello runnable");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
public class ThreadDemo3 {
    public static void main(String[] args) {
    Runnable runnable = new MyThread3();//runnable表示的这段代码是可执行的
    Thread t = new Thread(runnable);//还是需要搭配Thread类才可以在系统创建线程
        //或者直接new Thread(new MyThread3())
    t.start();//这种写法吧线程和执行的任务解耦合了
        while(true) {
            System.out.println("hello main");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
